
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>在Spring Boot项目中高效使用JPA的最佳实践 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>在Spring Boot项目中高效使用JPA的最佳实践 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Spring Boot项目中集成JPA，需要在pom.xml中引入哪个核心的starter依赖？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">为了在Spring Boot项目中使用JPA，需要在pom.xml文件中引入`spring-boot-starter-data-jpa`依赖。</div>
          </div>
          <div class="card-source">来源: 2.1 引入依赖</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">JPA配置属性`spring.jpa.hibernate.ddl-auto`的作用是什么？请列举文档中提到的四种常见值。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该属性用于控制Hibernate的DDL（Data Definition Language）操作模式。文档中提到的常见值有`create`、`update`、`create-drop`和`validate`。</div>
          </div>
          <div class="card-source">来源: 2.2 配置数据源和JPA属性</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">在JPA中，定义一个实体类（Entity）并映射到数据库表，必须使用哪两个基础注解？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">定义一个实体类，需要使用`@Entity`注解来标记该类，并使用`@Id`注解来指定其主键。</div>
          </div>
          <div class="card-source">来源: 3.1 定义实体类</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当需要执行复杂查询时，除了JPQL，JPA还支持哪种查询方式？如何通过注解来启用它？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">JPA还支持使用原生SQL进行查询。通过在`@Query`注解中设置`nativeQuery = true`来启用原生SQL查询。</div>
          </div>
          <div class="card-source">来源: 4.1 使用JPQL和原生SQL</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">什么是JPA中的投影查询？它主要用于解决什么问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">投影查询是一种只查询并加载实体部分字段的策略。它主要用于解决当只需要部分字段时，减少不必要数据加载以优化性能的问题。</div>
          </div>
          <div class="card-source">来源: 4.2 投影查询</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">JPA支持哪两种级别的缓存？其中哪一种是默认开启且作用于`EntityManager`级别的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">JPA支持一级缓存和二级缓存。其中，一级缓存是默认开启的，并且是作用于`EntityManager`级别上的缓存。</div>
          </div>
          <div class="card-source">来源: 4.3 缓存的使用</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Spring Boot应用中，如何为业务逻辑方法启用声明式事务管理？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过在方法或类上添加`@Transactional`注解，可以方便地为其启用声明式事务管理。</div>
          </div>
          <div class="card-source">来源: 5.1 声明式事务管理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Spring事务的默认传播机制是什么？请描述其行为。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">默认的事务传播机制是`REQUIRED`。其行为是：如果当前存在一个事务，则加入该事务；如果当前没有事务，则创建一个新的事务。</div>
          </div>
          <div class="card-source">来源: 5.2 事务传播机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何开启Hibernate的统计功能来监控JPA的性能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">首先，在`application.properties`中配置`spring.jpa.properties.hibernate.generate_statistics=true`。之后，便可以在应用程序中通过`EntityManagerFactory`获取`Statistics`接口来读取统计信息。</div>
          </div>
          <div class="card-source">来源: 6.1 使用Hibernate Statistics</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
